<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<![endif]-->
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
<script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <title>添加用户 - H-ui.admin v3.1</title>
    <meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>

<body>
    <article class="page-container">
        <form action="" method="post" class="form form-horizontal" enctype="multipart/form-data" id="form-member-add">
        	@foreach($data as $value)
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{$value->username}}" placeholder="" id="username" name="username" readonly style="background:#ccc">
                </div>
            </div>
            <div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>密码：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="password" class="input-text" autocomplete="off" value="******" placeholder="密码" id="password" readonly style="background:#ccc">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>性别：</label>
				<div class="formControls col-xs-8 col-sm-9 skin-minimal">
					<div class="radio-box">
						<input name="gender" type="radio" id="sex-1" value="1" @if($value->gender == '1') checked @endif>
						<label for="sex-1">男</label>
					</div>
					<div class="radio-box">
						<input type="radio" id="sex-2" name="gender" value="2" @if($value->gender == '2') checked @endif>
						<label for="sex-2">女</label>
					</div>
					<div class="radio-box">
						<input type="radio" id="sex-3" name="gender" value="3" @if($value->gender == '3') checked @endif>
						<label for="sex-3">保密</label>
					</div>
				</div>
			</div>
            <div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{{$value->mobile}}" placeholder="" id="mobile" name="mobile">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" placeholder="@" name="email" id="email" value="{{$value->email}}">
				</div>
			</div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">头像：</label>
                <div class="formControls col-xs-8 col-sm-9"> 
                    <div id="uploader-demo">
                        <!--用来存放item-->
                        <div id="fileList" class="uploader-list"></div>
                        <div id="filePicker">选择图片</div>
                        <!-- 隐藏域用于保存图片地址 -->
                        <input type="hidden" name="avatar" id="avatar" value="{{$value->avatar}}"/>
                        <img src="{{$value->avatar}}" alt="" class="aaa"/>
                        <script>
                        	var filePicker = document.querySelector('#filePicker');
                        	var aaa = document.querySelector('.aaa');
                        	
                        	filePicker.onclick=function(){
                        		aaa.src="";
                        	}
                        	
                        </script>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">所在城市：</label>
                <div class="formControls col-xs-8 col-sm-9"> 
                <span class="select-box" style="width: 110px">
				<select class="select country_id" size="1" name="country_id">
					<option value="0" class="qq">国家/地区</option>
					@foreach($country as $val)
						<option value="{{$val -> id}}" @if($val->id == $value->country_id ) selected @endif >{{$val -> area}}</option>
					@endforeach
				</select>
				</span>
				<span class="select-box" style="width: 110px">
				<select class="select province_id" size="1" name="province_id">
					<option value="0" selected>省份/州/直辖市</option>
					<option value="{{$pro_id}}" selected>{{$province[0]->area}}</option>
					
				</select>
				</span> 
				<span class="select-box" style="width: 110px">
				<select class="select city_id" size="1" name="city_id">
					<option value="0" selected>城市/区</option>
					<option value="{{$cit_id}}" selected>{{$city[0]->area}}</option>
				</select>
				</span> 
				<span class="select-box" style="width: 110px">
				<select class="select county_id" size="1" name="county_id">
					<option value="0" selected>县</option>
					<option value="{{$cou_id}}" selected>{{$county[0]->area}}</option>
				</select>
				</span>  
			</div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="status" type="radio" value="2" id="status-1" @if($value->status == '2') checked @endif>
                        <label for="status-1">正常</label>
                        
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="status-2" value="1" name="status" @if($value->status == '1') checked @endif>
                        	<label for="status-2">停用</label>
                    </div>
                </div>
            </div>
            {{csrf_field()}}
            @endforeach
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <!-- 引入webuploader相关外部文件 -->
    <link rel="stylesheet" type="text/css" href="/admin/lib/webuploader-0.1.5/webuploader.css">
    <script type="text/javascript" src="/admin/lib/webuploader-0.1.5/webuploader.js"></script>
    <script type="text/javascript">
    	
    // 图片上传demo
    jQuery(function() {
        var $ = jQuery,
            $list = $('#fileList'),
            // 优化retina, 在retina下这个值是2
            ratio = window.devicePixelRatio || 1,
            // 缩略图大小
            thumbnailWidth = 100 * ratio,
            thumbnailHeight = 100 * ratio,
            // Web Uploader实例
            uploader;
        // 初始化Web Uploader
        uploader = WebUploader.create({
            //自己主动携带的参数定义
            formData: {
                _token: "{{csrf_token()}}"
            },
            // 自动上传。
            auto: true,
            // swf文件路径
            swf: '/admin/lib/webuploader-0.1.5/Uploader.swf',
            // 文件接收服务端。
               server: '/admin/uploader/webuploader',
//          server: '/admin/uploader/qiniu',
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#filePicker',
            // 只允许选择文件，可选。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,png',
                //如果觉得选择文件比较慢可以修改成以下
                mimeTypes: 'image/gif,image/png,image/jpeg'
            }
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                    '<div id="' + file.id + '" class="file-item thumbnail">' +
                        '<img>' +
                        '<div class="info">' + file.name + '</div>' +
                    '</div>'
                    ),
                $img = $li.find('img');
            //移除之前全部的图片
            $('.thumbnail').remove();
            $list.append( $li );

            // 创建缩略图
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, thumbnailWidth, thumbnailHeight );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress span');
            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                        .appendTo( $li )
                        .find('span');
            }
            $percent.css( 'width', percentage * 100 + '%' );
        });

        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        // response表示ajax的返回值，如果是json格式可以直接使用
        uploader.on( 'uploadSuccess', function( file,response ) {
            //将返回的地址写入到表单中
            if(response.errorCode == '0'){
                //成功
                $('#avatar').val(response.path);
                layer.msg(response.message,{icon: 1});
            }else{
                layer.msg(response.message,{icon: 2});
            }
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，现实上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });
    $(function() {
    	//四联第1联
    	$('select[name=country_id]').click(function(){
    		//获取其当前的值
    		var country_id = $(this).val();
    		//发送ajax请求获取该国家/地区下属的内容（pid = country_id）
    		$.get('/admin/member/getAreasByPid',{pid: country_id},function(data){
    			//获取到数据之后将数据组装回页面
    			//循环得到全部需追加的option
    			var ops = '';
    			$.each(data,function(key,value){
    				ops += "<option value='" + value.id + "'>" + value.area + "</option>";
    			});
    			//先清除以前的老数据
    			$('select[name=province_id]').find('option:gt(0)').remove();
    			$('select[name=city_id]').find('option:gt(0)').remove();
    			$('select[name=county_id]').find('option:gt(0)').remove();
    			//追加操作
    			$('select[name=province_id]').append(ops);
    		},'json');    		
    	});

    	//四联第2联
    	$('select[name=province_id]').change(function(){
    		//获取其当前的值
    		var province_id = $(this).val();
    		//发送ajax请求获取该国家/地区下属的内容（pid = country_id）
    		$.get('/admin/member/getAreasByPid',{pid: province_id},function(data){
    			//获取到数据之后将数据组装回页面
    			//循环得到全部需追加的option
    			var ops = '';
    			$.each(data,function(key,value){
    				ops += "<option value='" + value.id  + "'>" + value.area + "</option>";
    			});
    			//先清除以前的老数据
    			$('select[name=city_id]').find('option:gt(0)').remove();
    			$('select[name=county_id]').find('option:gt(0)').remove();
    			//追加操作
    			$('select[name=city_id]').append(ops);
    		},'json');    		
    	});

    	//四联第3联
    	$('select[name=city_id]').change(function(){
    		//获取其当前的值
    		var city_id = $(this).val();
    		//发送ajax请求获取该国家/地区下属的内容（pid = country_id）
    		$.get('/admin/member/getAreasByPid',{pid: city_id},function(data){
    			//获取到数据之后将数据组装回页面
    			//循环得到全部需追加的option
    			var ops = '';
    			$.each(data,function(key,value){
    				ops += "<option value='" + value.id + "'>" + value.area + "</option>";
    			});
    			//先清除以前的老数据
    			$('select[name=county_id]').find('option:gt(0)').remove();
    			//追加操作
    			$('select[name=county_id]').append(ops);
    		},'json');    		
    	});

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-member-add").validate({
            rules: {
                username: {
                    required: true,
                    minlength: 2,
                    maxlength: 16
                },
                gender: {
                    required: true,
                },
                mobile: {
                    required: true,
                    isMobile: true,
                },
                email: {
                    required: true,
                    email: true,
                }
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "",
                    success: function(data) {
                    	if(data == '1'){
                    		layer.msg('编辑成功!', { icon: 1, time: 1000 },function(){
                    			var index = parent.layer.getFrameIndex(window.name);
				                //parent.$('.btn-refresh').click();
                                parent.location.href = parent.location.href;
				                parent.layer.close(index);
                    		});
                    	}else{
                    		layer.msg('编辑失败!', { icon: 2, time: 1000 });
                    	}
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', { icon: 1, time: 1000 });
                    }
                });
            }
        });
    });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>

</html>